<?php


namespace app\voip\func;


use app\voip\model\ECompany;

class CompanyFunc
{
    /**
     * @param $data
     * @return mixed
     * @throws \think\exception\DbException
     */
    static public function checkSave($data)
    {

        $resultData=[];
        foreach ($data as $key=>$val)
        {
            $res=ECompany::get(['company_name'=>$val]);
            if ($res){
                $resultData[$val]=$res->id;
            }else{
                $res=ECompany::create(['company_name'=>$val]);
                $resultData[$val]=$res->id;
            }
        }
        return $resultData;
    }

    /**
     * @param $where
     * @return ECompany|null
     * @throws \think\exception\DbException
     */
    static public function find($where)
    {
        return ECompany::get($where);
    }

}